package com.etnet.streamserver.util;

import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class XmlUtil {
    private static SAXReader reader = new SAXReader();
    private static Logger log = Logger.getLogger(XmlUtil.class.getName());

    public static Element getXMLRoot(String fullFileName) throws DocumentException {
        Document document = reader.read(fullFileName);
        return document.getRootElement();
    }

    public static String getConfigValue(String fullFileName, String nodeName) {
        try {
            Document document = reader.read(fullFileName);
            Element root = document.getRootElement();

            if (log.isDebugEnabled()) {
                log.debug("configuration file  key: " + nodeName + "value: " + root.elementText(nodeName));
            }
            return root.elementText(nodeName);
        } catch (DocumentException e) {
            log.error(e.getMessage(), e);
        }
        return null;
    }
}